<!DOCTYPE html>
<html>

	<head lang="en">
		<title>找攻略</title>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
		<link rel="stylesheet" href="/js/bootstrap/css/bootstrap.min.css">
		<script src="/js/plugins/jquery/jquery.min.js"></script>
		<script src="/js/bootstrap/js/bootstrap.min.js"></script>
		<link rel="stylesheet" href="/css/font/css/font-awesome.min.css" />
		<link rel="stylesheet" href="/css/reset.css" />
		<link rel="stylesheet" href="/css/myStrategyComment.css" />
		<script src="/js/plugins/jrender/jrender.js"></script>
		<link rel="stylesheet" href="/js/plugins/jquery-confirm/css/jquery-confirm.css">
		<script src="/js/plugins/jquery-confirm/js/jquery-confirm.js"></script>
		<script src="/js/common.js"></script>
		<link rel="stylesheet" href="css/test.css">


        <style>
            .btn {
                border-radius: 0px;
                font-weight: 100;
                cursor: pointer;
                display: inline-block;
                padding: 5px;
                font-size: 14px;
                font-family: '微软雅黑'
            }

            .btn-primary {
                color: #fff;
                text-shadow: 0 1px rgba(0, 0, 0, .1);
                background-image: -webkit-linear-gradient(top, #4d90fe 0, #4787ed 100%);
                background-image: -o-linear-gradient(top, #4d90fe 0, #4787ed 100%);
                background-image: -webkit-gradient(linear, left top, left bottom, from(#4d90fe),
                to(#4787ed));
                background-image: linear-gradient(to bottom, #4d90fe 0, #4787ed 100%);
                filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff4d90fe',
                endColorstr='#ff4787ed', GradientType=0);
                filter: progid:DXImageTransform.Microsoft.gradient(enabled=false);
                background-repeat: repeat-x;
                border: 1px solid #3079ed;
            }

            .btn-success {
                color: #fff;
                text-shadow: 0 1px rgba(0, 0, 0, .1);
                background-image: -webkit-linear-gradient(top, #35aa47 0, #35aa47 100%);
                background-image: -o-linear-gradient(top, #35aa47 0, #35aa47 100%);
                background-image: -webkit-gradient(linear, left top, left bottom, from(#35aa47),
                to(#35aa47));
                background-image: linear-gradient(to bottom, #35aa47 0, #35aa47 100%);
                filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff35aa47',
                endColorstr='#ff35aa47', GradientType=0);
                filter: progid:DXImageTransform.Microsoft.gradient(enabled=false);
                background-repeat: repeat-x;
                border: 1px solid #359947;
            }

            .gallery .img-item {
                position: relative;
            }

            .gallery .img-item .delete {
                position: absolute;
                display: block;
                width: 20px;
                height: 20px;
                color: #fff;
                background: rgba(0, 0, 0, 0.7);
                line-height: 20px;
                text-align: center;
                border-radius: 50%;
                top: 25px;
                right: 25px;
                cursor: pointer;
            }

            .img {
                width: 300px;
                margin: 20px;
            }
        </style>

	</head>

	<body>
	<div class="search-head">
		<div class="row nav-search">
			<div class="col">
				<a href="javascript:window.history.go(-1)">
					<span><i class="fa fa-chevron-left" ></i></span>
				</a>

			</div>
			<div class="col">
				<span>点评</span>
			</div>
			<div class="col"></div>
		</div>
	</div>

	<div class="comment">
		<!--<div class="container tag">
			<p>请为该旅游地选择合适的标签（大家都在评）</p>
			<div class="btn-group-toggle" data-toggle="buttons">
				<label class="btn btn-outline-danger ">
					<input type="checkbox" autocomplete="off" value="价格便宜"> 价格便宜
				</label>
				<label class="btn btn-outline-danger">
					<input type="checkbox" autocomplete="off" value="住宿方便"> 住宿方便
				</label>
				<label class="btn btn-outline-danger ">
					<input type="checkbox" autocomplete="off" value="旅游景点多"> 旅游景点多
				</label>
				<label class="btn btn-outline-danger ">
					<input type="checkbox" autocomplete="off" value="适合拍照">适合拍照
				</label>
				<label class="btn btn-outline-danger">
					<input type="checkbox"  autocomplete="off" value="吃的很多">吃的很多
				</label>
				<label class="btn btn-outline-danger">
					<input type="checkbox"  autocomplete="off" value="交通不方便">交通不方便
				</label>
			</div>

			<p>添加你自己的标签</p>
			<input name="myTags" class="form-control"  placeholder="请使用空格隔开标签，每个标签不超8个字"   />-->
			<div class="container imgs ">

				<form id="formdata" method="post" enctype="multipart/form-data">
					<p>你对该旅游地的评价</p>
					<ul id="list">
						<li class="list-item" title="很差"></li>
						<li class="list-item" title="差"></li>
						<li class="list-item" title="一般"></li>
						<li class="list-item" title="好"></li>
						<li class="list-item" title="很好"></li>
					</ul>
					<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
					<script src="js/score.js"></script>

					<hr />

					<input name="user.id" type="hidden" id="userId">
					<input name="travel.id" type="hidden" id="travelId">
					<input name="state" type="hidden" id="state" value="0">

					<p>更多评价内容</p>
					<textarea name="comment" class="form-control" rows="5" placeholder="请填写你对该旅游地的评价"></textarea>

					<p>上传图片</p>
					<div id="upload" class="btn btn-primary">选择图片</div>
					<div class="gallery" id="gallery"></div>
				</form>
				<input id="file" type="file" multiple style="display: none">
			</div>




		</div>
	</div>



	<div class="operation">
		<button class="btn" id="backBtn" onclick="window.history.go(-1)">放弃评价</button>
		<button class="btn" id="submitBtn">提交评价</button>
	</div>



    <script>
        var travelId = getParams().travelId;
        var userId = getUser().id;
        $("#userId").val(userId);
		$("#travelId").val(travelId);
        //创建数组保存图片
        var files = new Array();
        var id = 0;
        //选择图片按钮隐藏input[file]
        $("#upload").click(function() {
            $("#file").trigger("click");
        });
        //选择图片
        $("#file").change(function() {
            //获取所有图片
            var img = document.getElementById("file").files;
            //遍历
            for (var i = 0; i < img.length; i++) {
                //得到图片
                var file = img[i];
                //把图片存到数组中
                files[id] = file;
                id++;
                //获取图片路径
                var url = URL.createObjectURL(file);
                //创建img
                var box = document.createElement("img");
                box.setAttribute("src", url);
                box.className = 'img';
                //创建div
                var imgBox = document.createElement("div");
                imgBox.style.display = 'inline-block';
                imgBox.className = 'img-item';
                //创建span
                var deleteIcon = document.createElement("span");
                deleteIcon.className = 'delete';
                deleteIcon.innerText = 'x';
                //把图片名绑定到data里面
                deleteIcon.id = img[i].name;
                //把img和span加入到div中
                imgBox.appendChild(deleteIcon);
                imgBox.appendChild(box);
                //获取id=gallery的div
                var body = document.getElementsByClassName("gallery")[0];
                body.appendChild(imgBox);
                //点击span事件
                $(deleteIcon).click(function() {


                    //获取data中的图片名
                    var filename = $(this).attr('id');
                    //alert(filename);
                    //删除父节点
                    $(this).parent().remove();
                    var fileList = Array.from(files);
                    //遍历数组
                    for (var j = 0; j < fileList.length; j++) {
                        //通过图片名判断图片在数组中的位置然后删除
                        //alert(fileList[j].name+"111");
                        if (fileList[j].name == filename) {
                            fileList.splice(j, 1);
                            id--;
                            break;
                        }
                    }
                    files = fileList;
                });
            }
        });

        var n;
        $("#list").rating({
            num: n,
            type:'LightAll',
            chosen:function (n) {

                $("#state").val(n);
            }
        });


        //上传功能
        $("#submitBtn").click(

            function() {
                //创建FormData根据form
                var uploadFile = new FormData($("#formdata")[0]);
                //遍历图片数组把图片添加到FormData中
                for (var i = 0; i < files.length; i++) {
                    uploadFile.append("imgs", files[i]);
                    //alert(files[i].name);
                }
                    console.log(uploadFile);
                if ("undefined" != typeof (uploadFile) && uploadFile != null && uploadFile != "") {

                    //通过ajax上传

                    $.ajax({
                        url : "/travels/comment",
                        type : "post",
                        data : uploadFile, //把FormData作为参数

                        contentType : false, //不设置内容类型
                        processData : false,//不处理数据
                        success: function(data) {
                            if (data.success) {
                                /*alert("上传成功!");*/
                                window.location.href = "travelCatalogs.html?id="+travelId;
                            } else {
                                alert("上传失败!");
                            }
                        }
                    });
                }
            });





        $(function () {
            $('.star i').on('mouseenter',function () {
				$(".star i")
			});
		});



    </script>


	</body>


</html>